<?php
namespace Home\Controller;
use Think\Controller;
class PersonalCenterController extends CommonController {
    public function index() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
        $this->display('index');
    }
    public function RechargeBank() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
        $this->display('RechargeBank');
    }
    public function RechargeInfo() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
        $this->display('RechargeInfo');
    }
    public function RechargePay() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
        $this->display('RechargePay');
    }
    public function Pay() {
        $this->display('Pay');
    }
    public function transferAccounts() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
        $this->display('transferAccounts');
    }
    public function transferAccountslog() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
        $this->display('transferAccountslog');
    }
    public function UserList() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
        $this->list = M('user')->field('rmonery,rmonery2,ratiomoneyall,fmonery,fmoneryall,tmonery,tmonery2,tmoneryall')->where(array('Id' => $_SESSION['uid']))->find();
	//if(!$result) $this->redirect('/');
        $this->ref = 'http://' . $_SERVER['HTTP_HOST'] . '/join/' . $_SESSION['uid'];
        $this->display('UserList');
    }
    public function UserSumList() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
        $this->display('UserSumList');
    }
    public function RatioMoneyDataOne() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
        if (!IS_POST || !'IS_AJAX') {
            $this->redirect('/');
        }
        $data['Success'] = false;
        $list = M('user')->where(array('Id' => $_SESSION['uid']))->find();
        $aas = $list['rmonery'];
        if ($aas < 1) {
            $data['Msg'] = '暂无一级提成';
            $this->ajaxReturn($data);
        }
        M('user')->startTrans();
        $data2 = array('rmonery' => 0,);
        $result1 = M('user')->where(array('Id' => $_SESSION['uid']))->data($data2)->save();
        $result2 = M('user')->where(array('Id' => $_SESSION['uid']))->setInc('monery', $aas);
        $data2=array();
        $data2['type'] = 1;
        $data2['amount'] = $aas;
        $data2['info'] = '一级提成';
        $data2['time'] = time();
        $data2['uid'] = $_SESSION['uid'];
        $result3 = M('monery')->data($data2)->add();
        if ($result1 && $result2 && $result3) {
            $_SESSION['UserMoney'] = $_SESSION['UserMoney'] + $list['ratiomoney'];
            $data['Success'] = 'ture';
            M('user')->commit();
            $data['Msg'] = '一级提成领取成功';
            $_SESSION['UserMoney'] = $_SESSION['UserMoney'] + $aas;
        }
        $this->ajaxReturn($data);
    }
    public function RatioMoneyDataTwo() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
        if (!IS_POST || !'IS_AJAX') {
            $this->redirect('/');
        }
        $data['Success'] = false;
        $list = M('user')->where(array('Id' => $_SESSION['uid']))->find();
        $aas = $list['rmonery2'];
        if ($aas < 1) {
            $data['Msg'] = '暂无二级提成';
            $this->ajaxReturn($data);
        }
        M('user')->startTrans();
        $data2 = array('rmonery2' => 0,);
        $result1 = M('user')->where(array('Id' => $_SESSION['uid']))->data($data2)->save();
        $result2 = M('user')->where(array('Id' => $_SESSION['uid']))->setInc('monery', $aas);
        $data2=array();
        $data2['type'] = 1;
        $data2['amount'] = $aas;
        $data2['info'] = '二级提成';
        $data2['time'] = time();
        $data2['uid'] = $_SESSION['uid'];
        $result3 = M('monery')->data($data2)->add();
        if ($result1 && $result2 && $result3) {
            $_SESSION['UserMoney'] = $_SESSION['UserMoney'] + $list['ratiomoney'];
            $data['Success'] = 'ture';
            M('user')->commit();
            $data['Msg'] = '二级提成领取成功';
            $_SESSION['UserMoney'] = $_SESSION['UserMoney'] + $aas;
        }
        $this->ajaxReturn($data);
    }
    public function T1() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
        if (!IS_POST || !'IS_AJAX') {
            $this->redirect('/');
        }
        $data['Success'] = false;
        $list = M('user')->where(array('Id' => $_SESSION['uid']))->find();
        $aas = $list['tmonery'];
        if ($aas < 1) {
            $data['Msg'] = '暂无一级推广';
            $this->ajaxReturn($data);
        }
        M('user')->startTrans();
        $data2 = array('tmonery' => 0,);
        $result1 = M('user')->where(array('Id' => $_SESSION['uid']))->data($data2)->save();
        $result2 = M('user')->where(array('Id' => $_SESSION['uid']))->setInc('monery', $aas);
        $data2=array();
        $data2['type'] = 1;
        $data2['amount'] = $aas;
        $data2['info'] = '一级推广';
        $data2['time'] = time();
        $data2['uid'] = $_SESSION['uid'];
        $result3 = M('monery')->data($data2)->add();
        if ($result1 && $result2 && $result3) {
            $_SESSION['UserMoney'] = $_SESSION['UserMoney'] + $list['ratiomoney'];
            $data['Success'] = 'ture';
            M('user')->commit();
            $data['Msg'] = '一级推广领取成功';
            $_SESSION['UserMoney'] = $_SESSION['UserMoney'] + $aas;
        }
        $this->ajaxReturn($data);
    }
    public function T2() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
        if (!IS_POST || !'IS_AJAX') {
            $this->redirect('/');
        }
        $data['Success'] = false;
        $list = M('user')->where(array('Id' => $_SESSION['uid']))->find();
        $aas = $list['tmonery2'];
        if ($aas < 1) {
            $data['Msg'] = '暂无二级推广';
            $this->ajaxReturn($data);
        }
        M('user')->startTrans();
        $data2 = array('tmonery2' => 0,);
        $result1 = M('user')->where(array('Id' => $_SESSION['uid']))->data($data2)->save();
        $result2 = M('user')->where(array('Id' => $_SESSION['uid']))->setInc('monery', $aas);
        $data2=array();
        $data2['type'] = 1;
        $data2['amount'] = $aas;
        $data2['info'] = '二级推广';
        $data2['time'] = time();
        $data2['uid'] = $_SESSION['uid'];
        $result3 = M('monery')->data($data2)->add();
        if ($result1 && $result2 && $result3) {
            $_SESSION['UserMoney'] = $_SESSION['UserMoney'] + $list['ratiomoney'];
            $data['Success'] = 'ture';
            M('user')->commit();
            $data['Msg'] = '二级推广领取成功';
            $_SESSION['UserMoney'] = $_SESSION['UserMoney'] + $aas;
        }
        $this->ajaxReturn($data);
    }
    public function FS() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
        if (!IS_POST || !'IS_AJAX') {
            $this->redirect('/');
        }
        $data['Success'] = false;
        $list = M('user')->where(array('Id' => $_SESSION['uid']))->find();
        $aas = $list['fmonery'];
        if ($aas < 1) {
            $data['Msg'] = '暂无返水';
            $this->ajaxReturn($data);
        }
        M('user')->startTrans();
        $data2 = array('fmonery' => 0,);
        $result1 = M('user')->where(array('Id' => $_SESSION['uid']))->data($data2)->save();
        $result2 = M('user')->where(array('Id' => $_SESSION['uid']))->setInc('monery', $aas);
        $data2=array();
        $data2['type'] = 1;
        $data2['amount'] = $aas;
        $data2['info'] = '返水';
        $data2['time'] = time();
        $data2['uid'] = $_SESSION['uid'];
        $result3 = M('monery')->data($data2)->add();
        if ($result1 && $result2 && $result3) {
            $_SESSION['UserMoney'] = $_SESSION['UserMoney'] + $list['ratiomoney'];
            $data['Success'] = 'ture';
            M('user')->commit();
            $data['Msg'] = '返水领取成功';
            $_SESSION['UserMoney'] = $_SESSION['UserMoney'] + $aas;
        }
        $this->ajaxReturn($data);
    }
    public function GetUserList() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
        $list = M('user')->where(array('tid' => $_SESSION['uid']))->field('username,regtime,betcountmoney,status')->select();
        $data['rows'] = $list;
        $data['total'] = M('user')->where(array('tid' => $_SESSION['uid']))->count();
        $this->ajaxReturn($data);
    }
    public function WithdrawalCreateData() {
        $Money = (int)trim(I('post.Money', 0, 'int'));
        if (!$Money) return;
        $data['Success'] = false;
        $monery = $Money / C('CHA_GMONERY');
        if ($monery < C('MIX_WMONERY')) {
            $data['Msg'] = '最小提款金额为' . C('MIX_WMONERY') . '元';
            $this->ajaxReturn($data);
        }
        if ($monery > C('MAX_WMONERY')) {
            $data['Msg'] = '最大提款金额为' . C('MAX_WMONERY') . '元';
            $this->ajaxReturn($data);
        }
        $list = M('user')->where(array('Id' => $_SESSION['uid']))->find();
        if ($list['monery'] < $Money) {
            $data['Msg'] = '余额不足';
            $this->ajaxReturn($data);
        }
        $list = M('bank')->where(array('uid' => $_SESSION['uid']))->find();
        if (!$list) return;
        M('user')->startTrans();
        $data2 = array();
        $order = creatid();
        $times = time();
        $data2['uid'] = $_SESSION['uid'];
        $data2['BankName'] = $list['realbank'];
        $data2['BankNum'] = $list['card'];
        $data2['name'] = $list['name'];
        $data2['GameMoney'] = $Money;
        $data2['RealMoney'] = $monery * (1 - C('REC_MONERY'));
        $data2['uid'] = $_SESSION['uid'];
        $data2['order'] = $order;
        $result1 = M('withdrawal')->data($data2)->add();
        $data2 = array();
        $data2['type'] = 2;
        $data2['amount'] = $Money;
        $data2['info'] = $order . '提现';
        $data2['time'] = $times;
        $data2['uid'] = $_SESSION['uid'];
        $result2 = M('monery')->data($data2)->add();
        $result3 = M('user')->where(array('Id' => $_SESSION['uid']))->setDec('monery', $Money);
        if ($result1 && $result2 && $result3) {
            M('user')->commit();
            $data['Msg'] = '提现成功！';
            $data['Success'] = true;
        } else {
            M('user')->rollback();
            $data['Msg'] = '提现失败!';
        }
        $this->ajaxReturn($data);
    }
    public function WithdrawalList() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
        $this->display('WithdrawalList');
    }
    public function GetWithdrawalList() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
        $page = trim(I('post.page', 0, 'int'));
        $rows = trim(I('post.rows', 10, 'int'));
        $data['uid'] = $_SESSION['uid'];
        $list = M('withdrawal')->where($data)->page($page, $rows)->order('time desc')->select();
        $data2['total'] = M('withdrawal')->where($data)->count();
        $data2['rows'] = $list;
        $this->ajaxReturn($data2);
    }
    public function rtRMB() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
        $type = trim(I('post.type', 0, 'int'));
        if ($type == 2) {
            $data['Success'] = true;
            $monery = ($rmb / C('CHA_GMONERY')) * (1 - C('REC_MONERY'));
            $data['Obj'] = $monery;
        } else if ($type == 1) {
            $data['Success'] = true;
            $monery = $rmb * C('CHA_GMONERY');
            $data['Obj'] = $monery;
        } else {
            return;
        }
        $this->ajaxReturn($data);
    }

    public function getUserNiceName() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
        $username = trim(I('post.username', '', 'htmlspecialchars'));
        $type = trim(I('post.type', 0, 'int'));
        if (strlen($username) < 1) return;
        if ($type == 2) {

        } else if ($type == 1) {
            $nicename = M('user')->where(array('username' => $username))->getField('nicename');
            if(!$nicename){
                $nicename = '';
            }
            $data['Success'] = true;
            $data['Obj'] = $nicename;
        } else {
            return;
        }
        $this->ajaxReturn($data);
    }

    public function NewDetail() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
        $id = I('get.id', 1, 'int');
        $list = M('gonggao')->where(array('Id' => $id))->find();
        if ($list) {
            $this->title = $list['title'];
            $this->content = $list['content'];
        }
        $this->display('NewDetail');
    }
    public function NewsGG() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
        $type = I('post.type', 2, 'int');
        $list = M('gonggao')->order('Id desc')->field('Id,Title')->where(array('NewsType' => $type))->limit(10)->select();
        if ($list) {
            $data['Success'] = true;
            $data['Obj'] = $list;
            $this->ajaxReturn($data);
        }
    }
    public function UserInformation() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
        $this->display('UserInformation');
    }
    public function EmailAdd() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
        $this->display('EmailAdd');
    }
    public function EmailAddData() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
        $Title = substr(trim(I('post.Title')) , 0, 50);
        $EmailContent = substr(I('post.EmailContent') , 0, 200);
        if (!$Title || !$EmailContent) return;
        $time = time();
        $data2['uid'] = $_SESSION['uid'];
        $data2['title'] = $Title;
        $data2['username'] = $_SESSION['username'];
        $data2['CreateTime'] = $s3;
        $data2['tousername'] = 'admin';
        $data2['createtime'] = $time;
        $result1 = M('message')->data($data2)->add();
        if (!$result1) return;
        $data2 = array();
        $data2['username'] = $_SESSION['username'];
        $data2['mid'] = $result1;
        $data2['content'] = $EmailContent;
        $data2['time'] = $time;
        $result1 = M('messageadd')->data($data2)->add();
        $data['Success'] = true;
        $this->ajaxReturn($data);
    }
    public function EmailReply() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
        $id = trim(I('get.id', 0, 'int'));
        if (!$id) return;
        $list = M('message')->where(array('Id' => $id,'uid' => $_SESSION['uid']))->find();
        if (!$list) return;
        $list2 = M('messageadd')->where(array('mid' => $id))->order('time asc')->select();
        M('message')->where(array('Id' => $id))->data(array('status' => 2))->save();
        $this->list = $list;
        $this->list2 = $list2;
        $this->display('EmailReply');
    }
    public function EmailReplyData() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
        $id = trim(I('post.id', 0, 'int'));
        $EmailContent = substr(I('post.EmailReplyContent') , 0, 200);
        if (!$id) return;
        $list = M('message')->where(array('Id' => $id,'uid' => $_SESSION['uid']))->find();
        if (!$list) return;
        M('message')->where(array('Id' => $id))->data(array('status' => 0))->save();
        $data2['mid'] = $id;
        $data2['username'] = $_SESSION['username'];
        $data2['content'] = $EmailContent;
        $data2['time'] = time();
        $result1 = M('messageadd')->data($data2)->add();
        $data['Success'] = true;
        $this->ajaxReturn($data);
    }
    public function EmailList() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
        $this->display('EmailList');
    }
    public function GetEmailList() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
        $rows = I('post.rows',10,'int');
        $page =I('post.page',1,'int');
        $list=M('message')->order('createtime desc')->where(array('uid'=>$_SESSION ['uid']))->page($page, $rows)->select();
        $data['total']=M('message')->where(array('uid'=>$_SESSION ['uid']))->count();
        $data['rows']=$list;
        $this->ajaxReturn($data);
    }
    public function UpdatePwd() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
      $UserPwd =trim(I('post.UserPwd')) ;
      $NewPwd = trim(I('post.NewPwd'));
      $aNewPwd = trim(I('post.aNewPwd'));
      $date['Success']=false;
      if($NewPwd<>$aNewPwd){
        $date['Msg']="新密码与确认密码不一致";
        $this->ajaxReturn($date);
        }
      if($NewPwd==$UserPwd){
        $date['Msg']="新密码不能与旧密码一致";
        $this->ajaxReturn($date);
        }
      $user=M('user')->where(array('Id'=>$_SESSION ['uid']))->find();

      if(!$user) return;
      if(md5($UserPwd)<>$user['password']){
        $date['Msg']="原始密码输入错误，请重新输入";
        $this->ajaxReturn($date);       
        }
      if($user) $date['Success']=true;
      $this->ajaxReturn($date);
    }
    public function UpA() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
    }
    public function UserBetList() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
        $this->display('UserBetList');
    }
    public function GetUserBetList() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
        $pageSize = I('post.rows',10,'int');
        $pageNumber =I('post.page',1,'int');
        $list=M('bet')->order('Id desc')->where(array('UserID'=>$_SESSION ['uid']))->page($pageNumber, $pageSize)->select();
        $data['total']=M('bet')->where(array('UserID'=>$_SESSION ['uid']))->count();
        $data['rows']=$list;
        $this->ajaxReturn($data);
    }
    public function LotteryRecord() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
        $this->display('LotteryRecord');
    }
    public function CheckOn() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
      $list=M('bank')->where(array('uid' => $_SESSION ['uid']))->find();
      //print_r($list);die;
      if($list){
        $data['Success']=true;
        } else {
        $data['Success']=false;
        $data['Msg']='请先绑定您的银行卡号';
        }
      $this->ajaxReturn($data);
    }
    public function WithdrawalAdd() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
      $list=M('bank')->where(array('uid' => $_SESSION ['uid']))->find();
      if($list){
        $this->bankname=$list['realbank'];
        $this->card=$list['card'];
        $this->name=$list['name'];
        }
        $this->display('WithdrawalAdd');
    }
    public function BankAdd() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
        $this->display('BankAdd');
    }
    public function GetSumBank() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
      $list=M('conbank')->select();
      $this->ajaxReturn($list);
    }
    public function AddOrEditBank() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
        if (!IS_POST || !'IS_AJAX') {
            $this->redirect('/');
        }
      $BankName =trim(I('post.BankName')) ;
      $BankCard = trim(I('post.BankCard'));
      $aBankCard = trim(I('post.aBankCard'));
      $BankNickName = trim(I('post.BankNickName'));
      $data['Success']=false;
      if(!$BankName || !$BankCard || !$aBankCard|| !$BankNickName){
        $data['Msg']='信息有误，请检查您填写的内容';
        $this->ajaxReturn($data);
        }
      if($BankCard<>$aBankCard){
        $data['Msg']='您两次填写的银行卡不一致';
        $this->ajaxReturn($data);
        }
        $data0 = M('bank')->where(array('uid' => $_SESSION['uid']))->find();
      $list=M('bank')->where(array('uid' => $_SESSION ['uid']))->find();
      //print_r($list);die;
      if($list){
        $data['Msg']='您已经绑定过银行，每位会员只能绑定一张银行卡';
        $this->ajaxReturn($data);
        }
      $data = array();
      $data['uid']= $_SESSION ['uid'];
      $data['realbank']=$BankName;
      $data['card']=$BankCard;
      $data['name']=$BankNickName;
      $list=M('bank')->data($data)->add();
      if($list){
         $data['Success']=true;
         $data['Msg']='绑定成功';
        }
      $this->ajaxReturn($data);
    }
    public function SignInMoney() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
        $list=M('bank')->where(array('uid' => $_SESSION ['uid']))->find();
      //print_r($list);die;
      if($list){
        $data['Success']=true;
        } else {
        $data['Success']=false;
        $data['Msg']='请先绑定您的银行卡号';
        $data['Obj']=10;
        $this->ajaxReturn($data);
        }
       $date=time();
       $aaa = date('Y-m-d',$date);
       $bbb= strtotime($aaa)+86400;
       $ccc= $bbb;
       $bbb= $bbb-86400;
       $list=M('signin')->where(array('time' => array('between',array($bbb,$ccc)),'uid' => $_SESSION ['uid']))->find();

       if($list) return;
        if ($_SESSION['UserSignIn']) {
            M('monery')->startTrans();
        $data2['uid']=$_SESSION ['uid'];
        $data2['time']=time();
        $result1=M('signin')->data($data2)->add();
        $data2['amount']=$_SESSION ['UserSignIn'];
        $data2['type']=1;
        $data2['info']='签到+'.$_SESSION ['UserSignIn'].'金币';
        $result2=M('monery')->data($data2)->add();
            $result3=M('user')->where(array('Id' => $_SESSION ['uid']))->setInc('monery',$_SESSION ['UserSignIn']);
            if($result1 && $result2 && $result3){ 
                M('monery')->commit();
            $data['Msg']='签到成功';
                session('UserSignIn', null);
            } else {
                M('monery')->rollback();
           $data['Msg']='签到失败';
            }
        }
      $this->ajaxReturn($data);
    }
    public function UserSignIn() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
      $value = I('post.value',0,'int');
      $data=array();
      $data['Success']=false;
      $date=time();
      if($value==1){
          $monerys['id']=1;
          $monerys['oneMoney']=1000;
          $monerys['twoMoney']=1500;
          $monerys['threeMoney']=2500;
          $monerys['fourMoney']=5000;
          $monerys['fiveMoney']=8000;
          $monerys['sixMoney']=12000;
         $monerys['sevenMoney']=20000;
         $data['Success']=true;
         $aaa = date('Y-m-d',$date);
         $bbb= strtotime($aaa)+86400;
         $monerys['user_CheckNum']=0;
         for ($x=0; $x<=6; $x++) {
            $ccc= $bbb;
            $bbb= $bbb-86400;
            $list=M('signin')->where(array('time' => array('between',array($bbb,$ccc)),'uid' => $_SESSION ['uid']))->find();
            if(!$list){
              if($x==0) {
                $monerys['IsNo']=0;
                    }
              if($x>0) break;
                } else {
              if($x==0) $monerys['IsNo']=1;
              if($x>=0) {
                $monerys['user_CheckNum']=$monerys['user_CheckNum']+1;
                    }
                }
            }
            if($monerys['IsNo']==0){
            	$data['Msg']="";
            if($monerys['user_CheckNum']==0){
             	session('UserSignIn',1000);
            }elseif($monerys['user_CheckNum']==1){
             	session('UserSignIn',1500);    
            }elseif($monerys['user_CheckNum']==2){
                session('UserSignIn', 2500);
            }elseif($monerys['user_CheckNum']==3){
                session('UserSignIn', 5000);
            }elseif($monerys['user_CheckNum']==4){
                session('UserSignIn', 8000);
            }elseif($monerys['user_CheckNum']==5){
                session('UserSignIn', 12000);
            }elseif($monerys['user_CheckNum']==6){
                session('UserSignIn', 20000);
            } else {
                session('UserSignIn', 1000);
            	M('signin')->where(array('uid' => $_SESSION ['uid']))->delete();
            	}
        	}else{
           		$data['Msg']="亲，您今天已签过到了，手下留情！";
            }
        } else {
         $aaa = date('Y-m-d',$date);
         $bbb= strtotime($aaa)+86400;
         $list=M('denglu')->where(array('date' => array('between',array(date('Y-m-d',strtotime($aaa)),date('Y-m-d',strtotime($aaa)+86400))),'uid' => $_SESSION ['uid'],'leixin' => 1))->find();
         //echo $list;die;
         if(!$list){
             $monerys['user_CheckNum']=0;
             for ($x=0; $x<=6; $x++) {
                $ccc= $bbb;
                $bbb= $bbb-86400;
                $list2=M('signin')->where(array('time' => array('between',array($bbb,$ccc)),'uid' => $_SESSION ['uid']))->find();

                if(!$list2){
                  if($x==0) {
                    M('denglu')->where(array('date' => array('between',array(date('Y-m-d',strtotime($aaa)),date('Y-m-d',strtotime($aaa)+86400))),'uid' => $_SESSION ['uid'],'leixin' => 0))->data(array('leixin' => 1))->save();

                    $data['Success']=true;
                    $monerys['oneMoney']=1000;
                    $monerys['twoMoney']=1500;
                    $monerys['threeMoney']=2500;
                    $monerys['fourMoney']=5000;
                    $monerys['fiveMoney']=8000;
                    $monerys['sixMoney']=12000;
                    $monerys['sevenMoney']=20000;
                    $monerys['IsNo']=0;
                        }
                  if($x>0) break;
                    } else {
                  if($x==0) $monerys['IsNo']=1;
                  if($x>=0) {
                    $monerys['user_CheckNum']=$monerys['user_CheckNum']+1;
                        }
                    }
                }
             if($monerys['IsNo']==0){
                 $data['Msg']="";
                 if($monerys['user_CheckNum']==0){
                        session('UserSignIn', 1000);
                 }elseif($monerys['user_CheckNum']==1){
                        session('UserSignIn', 1500);
                 }elseif($monerys['user_CheckNum']==2){
                        session('UserSignIn', 2500);
                 }elseif($monerys['user_CheckNum']==3){
                        session('UserSignIn', 5000);
                 }elseif($monerys['user_CheckNum']==4){
                        session('UserSignIn', 8000);
                 }elseif($monerys['user_CheckNum']==5){
                        session('UserSignIn', 12000);
                 }elseif($monerys['user_CheckNum']==6){
                        session('UserSignIn', 20000);
                    } else {
                        session('UserSignIn', 1000);
                   M('signin')->where(array('uid' => $_SESSION ['uid']))->delete();
                    }
                }
            }
        }
    $data2['CreateTime']=array('between',array($_SESSION ['logintime2'],$date));
    $data2['UserID']=array('EQ', $_SESSION ['uid']);
	$_SESSION['sumMoney']=M('bet')->where($data2)->sum('winMoney');
	$list=M('user')->field('monery')->where(array('Id' => $_SESSION ['uid']))->find();
	$_SESSION['UserMoney']=$list['monery'];
	$_SESSION['ref']=M('user')->where(array('tid'=>$_SESSION ['uid']))->count();
	unset($data2,$list);
      $data['Obj']=$monerys;
      $this->ajaxReturn($data);
    }
    public function GetLotteryRecord() {
        $this->userinfo = M('user')->where(array('id' => $_SESSION ['uid']))->find();
        $list=M('lotteryrecord')->order('StartTime desc')->limit(100)->select();
        $data['success']=1;
        $data['list']=$list;
        $this->ajaxReturn($data);
    }

}